package com.hundsun.yr.universal.p2p.bean;

import android.text.TextUtils;

import com.hundsun.yr.universal.p2p.config.Config;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 信贷产品信息类--喔喔
 * @author tonglj
 *
 */
public class LoanProductsBean implements Serializable{
	private static final long serialVersionUID = 1L;
	/**
	 * 是否需要保证金代码
	 * NO or YES
	 */
	private String assureFlag;
	/**
	 * 是否允许超过授信截止日代码
	 * NO or YES
	 */
	private String beyondFlag;
	/**
	 * 审核周期
	 */
	private int checkPeriod;
	/**
	 * 创建时间
	 */
	private String createTime;
	/**
	 * 创建人
	 */
	private String creator;
	/**
	 * 递增金额
	 */
	private BigDecimal incrementAmount;
	/**
	 * 最大借款利率
	 */
	private BigDecimal maxBorrowRate;
	/**
	 * 最大借款金额
	 */
	private BigDecimal maxBrwAmount;
	/**
	 * 最大借款期限
	 */
	private int maxBrwPeriod;
	/**
	 * 最大募集期
	 */
	private int maxRaisePeriod;
	/**
	 * 最小借款利率
	 */
	private BigDecimal minBorrowRate;	
	/**
	 * 最小借款金额
	 */
	private BigDecimal minBrwAmount;
	/**
	 * 最小借款期限
	 */
	private int minBrwPeriod;
	/**
	 * 最小募集期
	 */
	private int minRaisePeriod;
	/**
	 * 外部流水号
	 */
	private String outSerialId;
	/**
	 * 是否需要抵押代码
	 * NO or YES
	 */
	private String pledgeFlag;
	/**
	 *  产品适用渠道代码
	 *  WEB("0", "WEB"),APP("1", "移动端"),WECHAT("2", "微信");
	 */
	private String[] productChannel;
	/**
	 *产品描述
	 */
//	private String productDesc;
	/**
	 *产品ID
	 */
	private String productId;
	/**
	 *产品名称
	 */
	private String productName;
	/**
	 * 产品类型代码
	 * PERSON("1", "个人"),  ORG("2", "机构");
	 */
	private String productType;
	/**
	 *协议编号 
	 */
	private String protocolId;
	/**
	 *还款方式代码
	 *ONCE_TIME("1","到期还本付息"), PROFIT_PRINCIPAL("2","先息后本"), MONTH_AMT("3","等额本息");
	 */
	private String[] refundWay;
	/**
	 * 状态
	 * CREATED("1", "已创建"),  UP_SHELF("2", "上架"), DELETED("3", "删除");
	 */
	private String status;
	/**
	 * 租户ID
	 */
	private String tenantId;
	
	/**
	 * 修改时间
	 */
	private String updateTime;
//	/**
//	 * 信贷费率列表
//	 */
	private String loanRates;
	/**
	 * 异常信息
	 */
	private String errorInfo;
	
	
	/**
	 * 获取月份列表
	 * 3,6,9,12,24,36
	 * @return
	 */
	public List<Integer> getMonths(){
		int minMonth = minBrwPeriod/Config.M_DAYS;
		boolean minFlag = minBrwPeriod%Config.M_DAYS == 0;
		int maxMonth = maxBrwPeriod/Config.M_DAYS;
		List<Integer> list = new ArrayList<Integer>();
		for (int i = minMonth; i <= maxMonth; i++) {
			if(i == 3||i == 6||i==9||i==12||i==24||i==36){
				list.add(i);
			}
		}
		if(minMonth == 3 && !minFlag){
			list.remove(0);
		}
		return list;
	}


	
//	public class LoanRate{
//		/**
//		 * 担保费率
//		 */
//		private double assureRate;
//		/**
//		 * 借款利率
//		 */
//		private double borrowRate;
//		/**
//		 * 截止天数
//		 */
//		private int endDay;
//		/**
//		 * 风险准备金费率
//		 */
//		private double riskRate;
//		/**
//		 * 服务费率
//		 */
//		private double serviceRate;
//		/**
//		 * 起始天数
//		 */
//		private int startDay;
//		public double getAssureRate() {
//			return assureRate;
//		}
//		public void setAssureRate(double assureRate) {
//			this.assureRate = assureRate;
//		}
//		public double getBorrowRate() {
//			return borrowRate;
//		}
//		public void setBorrowRate(double borrowRate) {
//			this.borrowRate = borrowRate;
//		}
//		public int getEndDay() {
//			return endDay;
//		}
//		public void setEndDay(int endDay) {
//			this.endDay = endDay;
//		}
//		public double getRiskRate() {
//			return riskRate;
//		}
//		public void setRiskRate(double riskRate) {
//			this.riskRate = riskRate;
//		}
//		public double getServiceRate() {
//			return serviceRate;
//		}
//		public void setServiceRate(double serviceRate) {
//			this.serviceRate = serviceRate;
//		}
//		public int getStartDay() {
//			return startDay;
//		}
//		public void setStartDay(int startDay) {
//			this.startDay = startDay;
//		}
//		
//	}
	
	public String getAssureFlag() {
		return assureFlag;
	}
	public void setAssureFlag(String assureFlag) {
		this.assureFlag = assureFlag;
	}
	public String getBeyondFlag() {
		return beyondFlag;
	}
	public void setBeyondFlag(String beyondFlag) {
		this.beyondFlag = beyondFlag;
	}
	public int getCheckPeriod() {
		return checkPeriod;
	}
	public void setCheckPeriod(int checkPeriod) {
		this.checkPeriod = checkPeriod;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public String getCreator() {
		return creator;
	}
	public void setCreator(String creator) {
		this.creator = creator;
	}

	

	public BigDecimal getIncrementAmount() {
		return incrementAmount;
	}



	public void setIncrementAmount(BigDecimal incrementAmount) {
		if(incrementAmount == null){
			incrementAmount = new BigDecimal(0);
		}
		this.incrementAmount = incrementAmount;
	}



	public BigDecimal getMaxBorrowRate() {
		return maxBorrowRate;
	}



	public void setMaxBorrowRate(BigDecimal maxBorrowRate) {
		this.maxBorrowRate = maxBorrowRate;
	}



	public BigDecimal getMaxBrwAmount() {
		return maxBrwAmount;
	}



	public void setMaxBrwAmount(BigDecimal maxBrwAmount) {
		this.maxBrwAmount = maxBrwAmount;
	}



	public BigDecimal getMinBorrowRate() {
		return minBorrowRate;
	}



	public void setMinBorrowRate(BigDecimal minBorrowRate) {
		this.minBorrowRate = minBorrowRate;
	}



	public BigDecimal getMinBrwAmount() {
		return minBrwAmount;
	}



	public void setMinBrwAmount(BigDecimal minBrwAmount) {
		this.minBrwAmount = minBrwAmount;
	}



	public int getMaxBrwPeriod() {
		return maxBrwPeriod;
	}
	public void setMaxBrwPeriod(int maxBrwPeriod) {
		this.maxBrwPeriod = maxBrwPeriod;
	}
	public int getMaxRaisePeriod() {
		return maxRaisePeriod;
	}
	public void setMaxRaisePeriod(int maxRaisePeriod) {
		this.maxRaisePeriod = maxRaisePeriod;
	}
	
	public int getMinBrwPeriod() {
		return minBrwPeriod;
	}
	public void setMinBrwPeriod(int minBrwPeriod) {
		this.minBrwPeriod = minBrwPeriod;
	}
	public int getMinRaisePeriod() {
		return minRaisePeriod;
	}
	public void setMinRaisePeriod(int minRaisePeriod) {
		this.minRaisePeriod = minRaisePeriod;
	}
	public String getOutSerialId() {
		return outSerialId;
	}
	public void setOutSerialId(String outSerialId) {
		this.outSerialId = outSerialId;
	}
	public String getPledgeFlag() {
		return pledgeFlag;
	}
	public void setPledgeFlag(String pledgeFlag) {
		this.pledgeFlag = pledgeFlag;
	}
	public String[] getProductChannel() {
		return productChannel;
	}
	public void setProductChannel(String[] productChannel) {
		this.productChannel = productChannel;
	}
//	public String getProductDesc() {
//		return productDesc;
//	}
//	public void setProductDesc(String productDesc) {
//		this.productDesc = productDesc;
//	}
	public String getProductId() {
		return productId;
	}
	public void setProductId(String productId) {
		this.productId = productId;
	}
	public String getProductName() {
		return productName;
	}
	public void setProductName(String productName) {
		this.productName = productName;
	}
	public String getProductType() {
		return productType;
	}
	public void setProductType(String productType) {
		this.productType = productType;
	}
	public String getProtocolId() {
		return protocolId;
	}
	public void setProtocolId(String protocolId) {
		this.protocolId = protocolId;
	}
	public String[] getRefundWay() {
		return refundWay;
	}
	public void setRefundWay(String[] refundWay) {
		this.refundWay = refundWay;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getTenantId() {
		return tenantId;
	}
	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}
	public String getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}
	public String getLoanRates() {
		return loanRates;
	}
	public void setLoanRates(String loanRates) {
		this.loanRates = loanRates;
	}
	
	
	/**
	 * 获取还款方式的中文
	 * @param name
	 * @return
	 */
	public String getRefundWayName(String name){
		if("ONCE_TIME".equals(name)){
			return "到期还本付息";
		}else if("PROFIT_PRINCIPAL".equals(name)){
			return "先息后本";
		}else if("MONTH_AMT".equals(name)){
			return "等额本息";
		}
		return "";
	}



	public String getErrorInfo() {
		return errorInfo;
	}



	public void setErrorInfo(String errorInfo) {
		this.errorInfo = errorInfo;
	}

	
	
	/**
	 * 显示还款方式
	 * @return
	 */
	public String displayReFundWay(){
		
		if(refundWay.length==0)return"";
		
		return getRefundWayName(refundWay[0]);
	}
	
	
	/**
	 * 显示借款期限单位
	 * @return
	 */
	public String displayTermType(){
		if(refundWay.length==0)return"天";
		if(TextUtils.equals(refundWay[0], "MONTH_AMT")){
			return "月";
		}else{
			return"天";
		}
	}
	
	
	
	/**
	 * 显示借款期限单位
	 * @return
	 */
	public String displayTerm(){
		if(refundWay.length==0)return minBrwPeriod+"~"+maxBrwPeriod+"天";
		if(TextUtils.equals(refundWay[0], "MONTH_AMT")){
			return String.valueOf(minBrwPeriod/30==0?1:minBrwPeriod/30)+"~"+maxBrwPeriod/30+"月";
		}else{
			return minBrwPeriod+"~"+maxBrwPeriod+"天";
		}
	}
	
}
